import config from '@/config'
import RequestBase from '@/utils/request.js'

const request = new RequestBase(config.specialWorkUrl)
const safetyReq = new RequestBase(config.safetyUrl)
const specialWorkUrl = new RequestBase(config.specialWorkUrl)
const baseReq = new RequestBase(config.baseUrl)
const activityReq = new RequestBase(config.activityUrl)

/**
 * @description 作业任务列表
 */
export function getSpwTaskList(query) {
  return request.get('/spw/ticket-apply/task-list', query)
}

/**
 * @description 作业票申请列表&记录
 */
export function getTicketApplyRecords(query) {
  return request.get('/spw/ticket-apply/list', query)
}

/**
 * @description 申请作业票
 */
export function addTicketApply(projectId, data) {
  return request.post(`/spw/ticket-apply/add/${projectId}`, data)
}

/**
 * @description 保存作业票草稿
 */
export function saveTicketApplyDraft(data) {
  return request.post('/spw/ticket-apply/draft/save', data)
}

/**
 * @description 获取作业票草稿信息
 */
export function getTicketApplyDraft(query) {
  return request.get('/spw/ticket-apply/draft', query)
}

/**
 * @description 获取作业票详情
 */
export function getTicketInfoById(ticketId) {
  return request.get(`/spw/ticket-apply/query/${ticketId}`)
}

/**
 * 获取作业票是否已经取消
 */
export function getTicketCancelInfo(ticketId) {
  return request.get(`/spw/ticket-apply/cancel/${ticketId}`)
}

/**
 * @description 重新申请作业票
 */
export function reapplyTicket(ticketId, data) {
  return request.post(`/spw/ticket-apply/re-add/${ticketId}`, data)
}
/**
 * @description 待分析作业票列表
 */
export function ticketAnalysis(data) {
  return request.get(`/mobile/spw/ticket/analysis/list`, data)
}

/**
 * @description 取消作业票申请
 */
export function cancelTicketApply(data) {
  return request.delete('/spw/ticket-apply/cancel', data)
}
/**
 * 获取作业票各个节点审核的详细信息
 */
export function getTicketActTypeDetail(ticketId) {
  return request.get(`/spw/ticket-apply/list/act/${ticketId}`)
}

/**
 * 流程节点详情
 */
export function getActivitiNodeDetail(procDefId, nodeId) {
  return request.get(`/activiti/node/${procDefId}/${nodeId}`)
}

/**
 * 获取作业票信息
 */
export function ticketList(query) {
  return request.get(`/mobile/spw/ticket/list`, query)
}

export function ticketLists(query) {
  return request.get(`/spw/ticket-apply/special/task/list/123`, query)
}

/**
 * 项目负责人转办
 */
export function turnDo(data) {
  return request.post(`/spw/ticket-review/directorTurn`, data)
}

/**
 * @description 更换监护人
 */
export function changeGuardian(data) {
  return request.put(`/spw/ticket-apply/person/change/guardian`, data)
}

/**
 * @description 更换项目负责人
 */
export function changeProjectDuty(data) {
  return request.put(`/spw/ticket-apply/person/change/project`, data)
}

// 本企业人员资质
export const getQualificationInfo = (id) => {
  return baseReq.get(`/basic-info/info/web/staff/qualify/${id}`)
}

// 查询承包商人员台账资质证书
export const getContractorQualify = (userId) => {
  return safetyReq.get(`/bsci/contractor-in-stock-member/getQualificationByMemberId/${userId}`)
}

// 查询承包商用户资质证书
export const getContractorUsrQualify = (userId) => {
  return safetyReq.get(`/bsci/contractor-in-stock-member/getQualificationByStaffUserId/${userId}`)
}

// 作业票-申请列表
export const getTicketApplyList = (params) => {
  return specialWorkUrl.get(`/mobile/spw/ticket/apply/list`, params)
}

// 作业票-项目信息
export const getTicketProInfo = (projectInfoId) => {
  return specialWorkUrl.get(`/mobile/spw/ticket/apply/info/${projectInfoId}`)
}

// 作业票-作业类型
export const getTicketWorkType = (projectInfoId) => {
  return specialWorkUrl.get(`/mobile/spw/ticket/apply/ticket/list/${projectInfoId}`)
}

// 作业票-危害介质列表
export const getGasLibs = (params) => {
  return request.get('/spw/hazard-media-lib/list', params)
}

// 作业票申请
export const ticketApply = (projectInfoId, data) => {
  return specialWorkUrl.post(`/mobile/spw/ticket/apply/applyTickets/${projectInfoId}`, data)
}

// 承包商
export const getContractor = (params) => {
  return safetyReq.get('/bsci/contractor/select-list', params)
}

// 提级审批人列表
export const upgradeApprovalList = (params) => {
  return baseReq.get('/portal/auth/staff/api/v1/list', params)
}

/**
 * @description 获取盲板抽堵关联
 */
export function geBlindPlateRelated(params) {
  return specialWorkUrl.get(`/spw/ticket-apply/list/relate-blank-plate`, params)
}

/**
 * @description 二级业务类别列表
 */
export function getParentFlag(parentFlag) {
  return activityReq.get(`/biz-config/sub-category/${parentFlag}`)
}

/**
 * 作业等级配置
 */
export function queryTicketWorkTypeLevel(workTypeFlag) {
  return request.get(`/spw/ticket-apply/level/list/${workTypeFlag}`)
}
/**
 * 查询作业票的全部签名列表
 */
export function getTicketSignatures(ticketId) {
  return request.get(`/spw/ticket-review/signatures/${ticketId}`)
}
/**
 * 获取分析作业票列表
 */
export function getTicketAnalyse(ticketId) {
  return request.get(`/spw/ticket-analyse/list/${ticketId}`)
}
